<template>
    <div class="default-main ba-table-box">

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields:'名称' })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'

defineOptions({
    name: 'routine/agreement',
})
const optBtn = defaultOptButtons(['edit', 'delete'])
const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/agreement/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: 'ID', prop: 'id', align: 'center', operator: '=', operatorPlaceholder: 'ID' },
            { label: '名称', prop: 'title', align: 'center', operator: '=', operatorPlaceholder: '名称' },
            {
                label: '生效时间',
                prop: 'effective_at',
                align: 'center',
                operator: '=',
                showOverflowTooltip: true,
            },
            { label:'排序', prop: 'sort', align: 'center', operator: '=', operatorPlaceholder: '排序' },
            {
                label:'是否禁用',
                prop: 'is_enabled',
                align: 'center',
                render: 'tag',
                custom: { 1: 'success', 0: 'danger' },
                replaceValue: { '1': '启用', '0': '禁用' },
            },
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: optBtn,
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined],
    },{
        defaultItems: {
            is_enabled: '1',
            sort:1,
            version:'1.0.0'
        },
    }

)

baTable.mount()
baTable.getIndex()

provide('baTable', baTable)
</script>

<style scoped lang="scss"></style>
